<?php

use think\migration\Migrator;
use think\migration\db\Column;

/**
 * Class Admin 管理员表
 */
class Admin extends Migrator
{
    public function change()
    {
        $table = $this->table('admin');
        $table->addColumn('username', 'string', ['limit'=>50, 'default'=>'', 'comment'=>'登陆账号']);
        $table->addColumn('mobile', 'string', ['limit'=>11, 'default'=>'', 'comment'=>'手机号']);
        $table->addColumn('password', 'string', ['limit'=>255, 'default'=>'','comment'=>'密码']);
        $table->addColumn('avatar', 'string', ['limit'=>255, 'default'=>'', 'comment'=>'头像']);
        $table->addColumn('register_ip', 'string', ['limit'=>20, 'default'=>'', 'comment'=>'IP']);
        $table->addColumn('login_time', 'integer', ['default'=>0, 'comment'=>'最后登陆时间']);
        $table->addColumn('last_login_ip', 'string', ['default'=>20, 'comment'=>'最后登陆IP']);
        $table->addColumn('login_num', 'integer', ['limit'=>4, 'default'=>0, 'comment'=>'登陆次数']);
        $table->addColumn('status', 'boolean', ['default'=>1, 'comment'=>'管理员状态(0:禁用,1:开启)']);
        $table->addColumn('create_time', 'integer', ['default'=>0]);
        $table->addColumn('update_time', 'integer', ['default'=>0]);

        $table->insert([
            'id' => 1,
            'username' => 'admin',
            'mobile' => '15900000000',
            'password' => md5('admin'),
            'avatar' => '/static/avatar/avatar.jpg',
            'register_ip' => '127.0.0.1',
            'last_login_ip' => '127.0.0.1',
            'create_time' => time()
        ]);
        $table->insert([
            'id' => 2,
            'username' => 'admin2',
            'mobile' => '15900000000',
            'password' => md5('admin2'),
            'avatar' => '/static/avatar/avatar.jpg',
            'register_ip' => '127.0.0.1',
            'last_login_ip' => '127.0.0.1',
            'create_time' => time()
        ]);

        $table->save();
    }
}
